package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.qurey.DestinationQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/destination")
public class DestinationController {

    @Autowired
    private IDestinationService destinationService;



    @RequestMapping("/list")
    private String list(Model model,@ModelAttribute("qo") DestinationQuery qo){
        Page<Destination> page= destinationService.query(qo);
        model.addAttribute("page", page);
        model.addAttribute("toasts",destinationService.queryToasts(qo.getParentId()));
        return "destination/list";
    }

    @GetMapping("listDests")
    @ResponseBody
    private Object listDests(){
        return destinationService.list();
    }




    @GetMapping("delete")
    @ResponseBody
    private Object delete(String id){
        destinationService.delete(id);
        return JsonResult.success();
    }

}
